package
{
	import core.Model;
	import core.events.GameEvent;
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;

	public class LayOut extends MovieClip
	{
		
		public var table:Table;
		public var title:Title;
		public var colorIndex:int = 1;
		/**
		 * 结束翻牌效果，最后一帧，以及坐标不对
		 * 配置上活动剪头
		 * 
		 * */
		public function LayOut()
		{
			super();
			this.title.addEventListener(MouseEvent.CLICK,titleClick);
			
			this.addEventListener(GameEvent.UPDATE_POINTS,updatePoints);
			
			this.addEventListener(GameEvent.UPDATE_TAKE,updateTake);
			
			this.updatePoints();
		}
		
		private function updatePoints(event:GameEvent = null):void {
			this.title.update(Model.instance.points);
		}
		
		public function titleClick(event:MouseEvent):void
		{
			var target:SimpleButton = event.target as SimpleButton;
			if(target == title.btn_colour)
			{
				changeColor();
			}
		}
		
		public function changeColor():void
		{
			this.colorIndex++;
			if(this.colorIndex > 3){
				this.colorIndex = 1;
			}
			this.table.gotoAndStop(this.colorIndex);
		}
		
		private function updateTake(event:GameEvent):void {
			this.title.updateTake(Model.instance.take);
		}
		
	}
}